<?php

declare(strict_types=1);

namespace app\model;

use think\Model;
use think\facade\Db;

/**
 * @mixin \think\Model
 */
class Users extends Model
{
    //获取单一数据
    public static function where($where = "", $field = '*')
    {
        $find = Db::name('users')->where($where)->field($field)->find();
        return $find;
    }
    //添加数据
    public static function add($data)
    {
        $data['add_date'] = time();
        $res = Db::name('users')->insert($data);
        return $res;
    }
    //编辑数据
    public static function edit($data)
    {
        $data['rep_date'] = time();
        $res = Db::name('users')->update($data);
        return $res;
    }
    //获取多数据
    public static function list($w = "", $page, $limit)
    {
        $count = Db::name('users')->count();
        //计算出从那条开始查询
        $tol = ($page - 1) * $limit;
        $res = Db::name('users')->where($w)->limit($tol, $limit)->order('add_date')->select();
        return ['data' => $res, 'count' => $count];
    }
    //添加数据返回ID
    public static function addid()
    {
        $data['add_date'] = time();
        $res = Db::name('users')->insertGetId($data);
        return $res;
    }
}
